'use strict';
Scene.create('main', function() {
	let { panels, graf, screenSize, netmap, CameraMoveingObject } = global_ns;
	let { Node, Spatial, Sprite } = nodes_ns;
	let { DataNode, Panel, PanelViewer } = panels_ns;
	let { Value } = value_ns;
	
	let cameraMoveingObject = new CameraMoveingObject(main.camera);
	
	let rootNode = null;
	
	let resizeHandler = e => {
		netmap.size.set(screenSize);
	};
	
	
	let get;


	let vvv = 2;
	//===============init===============//
	this.init = () => {
		rootNode = new Node({
			name: 'root',
		});
		rootNode._isRenderDebug = 1;
		
		get = rootNode.getChild.bind(rootNode);
		
		
		
		function programm() {
			let sys = require('system');
		
			sys.on('stdin', () => {
				std.out = std.in + 2;
				console.log(std.out, std.in);
			});
		};
		
		
		panels.push(rootNode.appendChild(new PanelViewer({
			name: 'Panel1',
			
			data: programm,
			
			pos: vec2(50, 30),
			size: vec2(150, 70)
		})));
		
		panels.push(rootNode.appendChild(new PanelViewer({
			name: 'Panel2',
			
			data: programm,
			
			pos: vec2(250, 70),
			size: vec2(150, 70)
		})));
		
	//	let pp = get('Panel2').node.data.evaluate();
		
		
		panels.push(rootNode.appendChild(new PanelViewer({
			name: 'Panel3',
			
			data: programm,
			
			pos: vec2(450, 50),
			size: vec2(150, 70)
		})));
		
	//	get('Panel3').node.bind(get('Panel2').node).bind(get('Panel1').node);
		
		
		
		
		resizeHandler();
		cvs.on('resize', resizeHandler);
		
		
		rootNode.ready();
		
		cfg.radius = 5;
		console.log('main scene inited');
	};


	//===============update===============//
	this.update = function(dt) {
		//=======prePROCES=======//--vs--//=======EVENTS=======//
		cameraMoveingObject.update(touches, main.camera);
		//==================================================//


		//=======PROCES=======//--vs--//=======UPDATE=======//"
		gui_ns.handleInteractions(touches, main);
		
		get('Panel2').pos.y -= 0.1;
		
		rootNode.update(dt);
		//==================================================//


		//==========DRAW==========//--vs--//==========RENDER==========//
		main.ctx.clearRect(0, 0, cvs.width, cvs.height);
		
		netmap.draw(main);
		
		rootNode.render(main);
		
		gui_ns.render(main);
		
		main.save();
		main.fillStyle = '#ffffff';
		main.font = 'bold 15px Arial';
		main.ctx.fillText('FPS: '+(1000/dt).toFixed(2), 20, 20);
		main.restore();
	}; //==============================//


	this.exit = () => console.log('exited');
});


Scene.run('main');
